package com.tanhua.server.controller;

import com.aliyuncs.ecs.model.v20140526.DescribeClassicLinkInstancesResponse;
import com.tanhua.model.mongodto.RecommendUserDto;
import com.tanhua.model.vo.NearUserVo;
import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.TodayBest;
import com.tanhua.server.service.TanHuaService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/tanhua")
@Slf4j
public class TanHuaController {

    @Autowired
    private TanHuaService tanHuaService;

    /**
     * 查询当前用户今日佳人
     * @return
     */
    @GetMapping("/todayBest")
    public ResponseEntity todayBest(){

        TodayBest todayBest = tanHuaService.todayBest();

        return ResponseEntity.ok(todayBest);
    }

    /**
     * 推荐朋友
     * @return
     */
    @GetMapping("/recommendation")
    public ResponseEntity recommendation(RecommendUserDto recommendUserDto){
        log.info(recommendUserDto.toString());

        PageResult pageResult = tanHuaService.recommendation(recommendUserDto);

        return ResponseEntity.ok(pageResult);
    }

    /**
     * 查询佳人详情信息
     * @param personalId
     * @return
     */
    @GetMapping("/{id}/personalInfo")
    public ResponseEntity personalInfo(@PathVariable("id") Long personalId){

        TodayBest todayBest = tanHuaService.personalInfo(personalId);

        return ResponseEntity.ok(todayBest);
    }

    /**
     * 查询陌生人问题
     * @param userId
     * @return
     */
    @GetMapping("/strangerQuestions")
    public ResponseEntity strangerQuestions(Long userId){
        String question = tanHuaService.strangerQuestions(userId);
        return ResponseEntity.ok(question);
    }

    /**
     * 回复陌生人问题
     * @param map
     * @return
     */
    @PostMapping("/strangerQuestions")
    public ResponseEntity replyQuestions(@RequestBody Map map){
        Integer userId = (Integer) map.get("userId");
        String reply = (String) map.get("reply");
        tanHuaService.replyQuestions(userId,reply);

        return ResponseEntity.ok(null);
    }

    /**
     * 推荐列表查询
     * @return
     */
    @GetMapping("/cards")
    public ResponseEntity cards(){
        List<TodayBest> todayBestList = tanHuaService.cards();

        return ResponseEntity.ok(todayBestList);
    }

    /**
     * 探花-喜欢
     * @param likeId
     * @return
     */
    @GetMapping("/{id}/love")
    public ResponseEntity love(@PathVariable("id") Long likeId){
        tanHuaService.like(likeId);

        return ResponseEntity.ok(null);
    }

    /**
     * 探花-不喜欢
     * @return
     */
    @GetMapping("/{id}/unlove")
    public ResponseEntity unLove(@PathVariable("id")Long unlikeUserId){
        tanHuaService.unlike(unlikeUserId);

        return ResponseEntity.ok(null);
    }

    /**
     * 搜附近
     * @return
     */
    @GetMapping("/search")
    public ResponseEntity search(String gender,
                                 @RequestParam(defaultValue = "2000") String distance){
        List<NearUserVo> vos = tanHuaService.searchUser(gender,distance);
        return ResponseEntity.ok(vos);
    }
}
